init();
var ul;
function init(){
    var ul=document.querySelector(".couponproduct");
    ul.addEventListener("click",clickHandler);
    
}





let href = location.href;
function getUrlParams(url) {  
    let reg = /^[^\s]+\?([^&\s\d]+=[^\s]+)*/
    let match = reg.exec(url)
    match = match[1]
    if (!match) {
        console.warn("没有匹配到相应的query参数")
        return null
    }
   
    let queryString = decodeURI(match);
   
    let queryArr = queryString.split("&");
   
    let queryParamsObj = {}
    queryArr.forEach(item => {
        let itemArr = item.split("=")
        queryParamsObj[itemArr[0]] = itemArr[1]
    })
   
    return queryParamsObj
}
let qr = getUrlParams(href)
let { couponid } = qr;



   $.ajax({
    url:"http://chst.vip:1234/api/getcouponproduct",
    data:{
        couponid
    }
}).then(res=>{
    let html=res.result.reduce((value,item)=>{
        return value+`     
        <li class="couponli">
            <a href="#">
            <div class="img">
            ${item.couponProductImg}
            </div>
            <div class="right">
            <h4>${item.couponProductName}</h4>
            <P>${item.couponProductPrice}</P><br>
            <i>${item.couponProductTime}</i>
            </div>
            </a>
        </li>
        `
    },"")
    $(".couponproduct").html(html)
    
}) 

function clickHandler(e){
    var num=e.target.parentElement.parentElement.parentElement;
    if($(num).attr("class")!== "couponli") return 
    $(".mask").animate({top:"0"},300);
    $("#maskimg").attr("src",$(num).find('img').attr('src'))
    $("button").on("click",clickBn)
}


function clickBn(){
    if($(this).attr("class")=="closemask"){
        $(".mask").animate({top:"-100%"},300);
    }
    if($(this).attr("class")=="leftbn"){
       
    }
    if($(this).attr("class")=="right"){

    }
}














